package com.wsc.wisdomchinaqinghe.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wsc.wisdomchinaqinghe.R;

import java.util.List;

/**
 * 四大功能适配器
 * Created by ${wangtao} on 2017/2/24.
 */

public class PeopleControlTypeAdapter extends BaseAdapter {
    private List<String> objects;
    private Context context;
    private LayoutInflater layoutInflater;
    private Integer positionFlag;

    public PeopleControlTypeAdapter(Context context, List<String> objects) {
        this.objects = objects;
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public String getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.item_peoplecontrol, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        ViewHolder viewHolder=(ViewHolder)convertView.getTag();
        String text=getItem(position);
        viewHolder.itemHeadName.setText(text);
        if(positionFlag!=null)
        {
            if(positionFlag==position)
            {
                viewHolder.itemHeadName.setTextColor(context.getResources().getColor(R.color.white));
                viewHolder.itemHeadName.setBackgroundColor(context.getResources().getColor(R.color.OK_color));
            }else {
                viewHolder.itemHeadName.setTextColor(context.getResources().getColor(R.color.text_color_one));
                viewHolder.itemHeadName.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.retrangepeoplecontrol));
            }
        }

        return convertView;
    }

    public void setPosition(int position)
    {
        this.positionFlag=position;
    }

    protected class ViewHolder {
        private TextView itemHeadName;

        public ViewHolder(View view) {
            itemHeadName = (TextView) view.findViewById(R.id.item_sida_gongnneg_head_name);
        }
    }
}
